//package ui;
//
//import javafx.event.ActionEvent;
//import javafx.fxml.FXML;
//import javafx.fxml.Initializable;
//import javafx.scene.control.TableView;
//import javafx.scene.control.TextField;
//import util.CapsJdbc;
//import util.CapsRes;
//import util.CapsTableView;
//
//import java.net.URL;
//import java.text.ParseException;
//import java.text.ParsePosition;
//import java.text.SimpleDateFormat;
//import java.util.*;
//
//public class Tea_roomMgr implements Initializable {
//
//   @FXML
//   private TextField rno;
//
//   @FXML
//   private TextField tno;
//
//   @FXML
//   private TextField tea_datetime;
//
//   @FXML
//   private TableView<Map<String,String>> tea_roomTv;
//
//private Date settime;
//
//   @FXML
//   private void saveTea_room(ActionEvent event) {
//      List<Object> params = new ArrayList<>(Arrays.asList(tno.getText(),rno.getText(),tea_datetime.getText()));
// /*     List<Object> params = new ArrayList<>(Arrays.asList(tno.getText(),rno.getText(),this.setSettime(tea_datetime.getText())));*/
//      String updSql = "update tea_room_rel set tno=?,tea_datetime=? where rno=?";
//      CapsRes capsRes = CapsJdbc.execSQL(updSql,params);
//      if (capsRes.getTtlNum() < 1) {
//         String addSql = "insert into tea_room_rel(tno,rno,tea_datetime) values(?,?,?)";
//         CapsJdbc.execSQL(addSql,params);
//      }
//   }
//
//
//   @Override
//   public void initialize(URL url, ResourceBundle rb) {
//      String strSQL = "select rno,tno,tea_datetime from tea_room_rel";
//      CapsRes capsRes = CapsJdbc.execSQL(strSQL,null);
//      CapsTableView.dealTableView(capsRes, tea_roomTv);
//      CapsTableView.addButtonToTable( tea_roomTv,(recMap,idCol) -> {
//         String delSql = "delete from tea_room_rel where rno = ?";
//         List<Object> params = new ArrayList<>(2);
//         params.add(recMap.get("RNO"));
//         CapsJdbc.execSQL(delSql,params);
//      },(recMap,idCol) -> {
//           rno.setText(recMap.get("RNO"));
//           tno.setText(recMap.get("TNO"));
//           tea_datetime.setText(recMap.get("TEA_DATETIME"));
//      });
//   }
//}

package ui;

import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.control.TableView;
import javafx.scene.control.TextField;
import util.CapsJdbc;
import util.CapsRes;
import util.CapsTableView;

import java.net.URL;
import java.util.*;

public class Tea_roomMgr implements Initializable {

   @FXML
   private TextField rno;

   @FXML
   private TextField tno;

   @FXML
   private TextField tea_datetime;
   
   @FXML
   private TextField tea_roomCond;

   @FXML
   private TableView<Map<String,String>> tea_roomTv;


   @FXML
   private void saveTea_room(ActionEvent event) {
      List<Object> params = new ArrayList<>(Arrays.asList(tno.getText(),tea_datetime.getText(),rno.getText()));
      String updSql = "update tea_room_rel set tno=?,tea_datetime=? where rno=?";
      CapsRes capsRes = CapsJdbc.execSQL(updSql,params);
      if (capsRes.getTtlNum() < 1) {
         String addSql = "insert into tea_room_rel(tno,tea_datetime,rno) values(?,?,?)";
         CapsJdbc.execSQL(addSql,params);
      }
      this.dealQry(null);
   }

   @FXML
   private void qryByTea_room(ActionEvent event) {
      this.dealQry(tea_roomCond.getText());
   }
   
   @Override
   public void initialize(URL url, ResourceBundle rb) {
	   this.dealQry(null);
   }

  private void dealQry(String tea_roomRno) {
	  tea_roomTv.setItems(null);
	  tea_roomTv.getColumns().clear();
      String strSQL = "select rno,tno,tea_datetime from tea_room_rel";
      List<Object> params = null;
      if (null != tea_roomRno && tea_roomRno.length() > 0) {
         strSQL += " where rno like ?";
         params = new ArrayList<>(1);
         params.add(tea_roomRno+"%");
      } 
      CapsRes capsRes = CapsJdbc.execSQL(strSQL,params);
      CapsTableView.dealTableView(capsRes, tea_roomTv);
      CapsTableView.addButtonToTable( tea_roomTv,(recMap,idCol) -> {
         String delSql = "delete from tea_room_rel where rno = ?";
         List<Object> delparams = new ArrayList<>(1);
         delparams.add(recMap.get("rno"));
         CapsJdbc.execSQL(delSql,delparams);
         this.dealQry(null);
      },(recMap,idCol) -> {
           rno.setText(recMap.get("rno"));
           tno.setText(recMap.get("tno"));
           tea_datetime.setText(recMap.get("tea_datetime"));
      });
   }
}
